package com.limh.readers.adapter

import android.content.Context
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.jude.rollviewpager.adapter.DynamicPagerAdapter
import com.limh.readers.bean.Article
import com.squareup.picasso.Picasso


/**
 * Function:
 * author: limh
 * time:2017/8/2
 */
class RollAdapter(var context: Context, var data: MutableList<Article>) : DynamicPagerAdapter() {

    override fun getView(container: ViewGroup?, position: Int): View {
        val imageView = ImageView(container!!.context)
        if (!TextUtils.isEmpty(data[position].artPic))
            Picasso.with(context).load(data[position].artPic).into(imageView)
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        imageView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT)
        return imageView
    }

    override fun getCount(): Int {
        return data.size
    }

}